package com.example.smartcity_poverty.ui.AllService.TakeOutTr.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import com.example.smartcity_poverty.App.Companion.url
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.Repository.toApi
import com.example.smartcity_poverty.logic.util.Util
import com.example.smartcity_poverty.logic.util.Util.show
import kotlinx.android.synthetic.main.activity_shop_message_view.*


/**
 * 商家信息页面
 */
class ShopMessageViewActivity : AppCompatActivity() {

    // 店家id
    private val shopId by lazy { intent.getStringExtra("id") }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_shop_message_view)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        title = "商家信息"

        // 获取店家详细信息
        getShopContentImp()
    }

    /**
     * 获取店家详细信息
     */
    private fun getShopContentImp() {
        // 开启协程
        coroutine() {
            val response = toApi.getShopContent(shopId?.toInt()!!)
            // 打印店家名称
            runOnUiThread {
                // 加载商家图片
                Util.glide(url + response.data.imgUrl, imgShop)
            }

        }
    }

    /**
     * 销毁页面
     */
    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}